package com.hd.trans.utils.thread;

import android.os.Handler;
import android.os.HandlerThread;

import androidx.annotation.NonNull;

/**
 * 自定义ui线程
 */
public class CustomUiThread {

    private static CustomUiThread sInstance;

    private final Handler mHandler; // 自定义UI线程Handler

    public CustomUiThread() {
        HandlerThread handlerThread = new HandlerThread("custom-ui-thread");
        handlerThread.start();
        mHandler = new Handler(handlerThread.getLooper());
    }


    @NonNull
    public static CustomUiThread getInstance() {
        if (sInstance != null) {
            return sInstance;
        }
        synchronized (CustomUiThread.class) {
            if (sInstance == null) {
                sInstance = new CustomUiThread();
            }
        }
        return sInstance;
    }

    public void post(Runnable runnable){
        mHandler.post(runnable);
    }

    public void postDelayed(Runnable runnable, long delayMillis){
        mHandler.postDelayed(runnable, delayMillis);
    }

    public interface Callback<T>{
        void onThreadCallback(T obj);
    }


}
